package org.mushroomdb.client.gui;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Rectangle;

import javax.swing.ImageIcon;

import org.apache.log4j.Logger;

public class BinaryExPlanTree {
	private Node root = null;
	
	public Node getRoot() { return root; }
	
	public Node addRoot(String operationName, ImageIcon operationImg, String attributes) {
		root = new Node(operationName, operationImg, attributes);
		return root;
	}

	public Node addLeft(Node n, String operationName, ImageIcon operationImg, String attributes) {
		return n.setLeft(operationName, operationImg, attributes);
	}

	public Node addRight(Node n, String operationName, ImageIcon operationImg, String attributes) {
		return n.setRight(operationName, operationImg, attributes);
	}
	
//	public Node addBelow(Node n, Image operationImg, String attributes) {
//		n.setLeft(new Node(operationImg, attributes));
//	}

	
	/**
	 * Nodo del arbol
	 */
	public class Node {
		private String operationName = null;
		private ImageIcon operationImg = null;
		private String attribs = null;	
		private Node left = null;
		private Node right = null;
		private Rectangle location = null;
		private Dimension subTreeSize;
		
		public Node(String operationName, ImageIcon operationImg, String attribs) {
			this.operationName = operationName;
			this.operationImg = operationImg;
			this.attribs = attribs;
		}
		
		public Node setLeft(String operationName, ImageIcon operationImg, String attributes) {
			left = new Node(operationName, operationImg, attributes);
			Logger.getLogger(this.getClass()).debug(" atts " + attributes);
			return left;
		}
		
		public Node setRight(String operationName, ImageIcon operationImg, String attributes) {
			right = new Node(operationName, operationImg, attributes);
			return right;
		}

		public Node getLeft() { 
			return left; 
		}

		public Node getRight() { 
			return right; 
		}
		
		public String getOperationName() { 
			return operationName; 
		}

		public ImageIcon getImageIcon() { 
			return operationImg; 
		}
		
		public String getAttributes() {
			return attribs;
		}

		public void setLocation(Rectangle r) {
			this.location = r;
		}
		
		public Rectangle getLocation() {
			return location;
		}

		public void setSubtreeSize(Dimension subtreeSize) {
			this.subTreeSize = subtreeSize;
		}

		public Dimension getSubtreeSize() {
			return subTreeSize;
		}
	}
}